package com.wyzz.hr.action;

import java.util.Map;

import com.wyzz.hr.base.BaseAction;
import com.wyzz.hr.util.DatabaseSysConfigManager;
import com.wyzz.hr.util.SysConfigManager;

public class ConfigProfile extends BaseAction {

	public ConfigProfile() {
		dbConfigManager = DatabaseSysConfigManager.getInstance();
	}

	public String execute() throws Exception {
		if (!hasAuth(961, new int[0])) {
			addErrorInfo("\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u65E0\u6743\u8FDB\u5165\u8BE5\u9875\u9762\uFF01");
			return "noauth";
		} else {
			Map dbMap = dbConfigManager.getProperties();
			sys_contract_expire_remind = (String) dbMap
					.get("sys.contract.expire.remind");
			sys_contract_expire_remind = SystemConfigInit.getValue(
					sys_contract_expire_remind, "45");
			sys_birthday_remind = (String) dbMap.get("sys.birthday.remind");
			sys_birthday_remind = SystemConfigInit.getValue(
					sys_birthday_remind, "30");
			sys_trial_expire_remind = (String) dbMap
					.get("sys.trial.expire.remind");
			sys_trial_expire_remind = SystemConfigInit.getValue(
					sys_trial_expire_remind, "30");
			sys_salary_joinyear_calc = (String) dbMap
					.get("sys.salary.joinyear.calc");
			sys_salary_joinyear_calc = SystemConfigInit.getValue(
					sys_salary_joinyear_calc, "15");
			sys_profile_save_history = (String) dbMap
					.get("sys.profile.save.history");
			sys_profile_save_history = SystemConfigInit.getValue(
					sys_profile_save_history, "0");
			sys_position_max_exceed = (String) dbMap
					.get("sys.position.max.exceed");
			sys_position_max_exceed = SystemConfigInit.getValue(
					sys_position_max_exceed, "0");
			return "success";
		}
	}

	public String executeUpdate() throws Exception {
		if (!hasAuth(961, new int[0])) {
			addErrorInfo("\u5BF9\u4E0D\u8D77\uFF0C\u60A8\u65E0\u6743\u8FDB\u5165\u8BE5\u9875\u9762\uFF01");
			return "noauth";
		}
		try {
			Map dbMap = dbConfigManager.getProperties();
			if (!((String) dbMap.get("sys.contract.expire.remind"))
					.equals(sys_contract_expire_remind))
				dbConfigManager.setProperty("sys.contract.expire.remind",
						sys_contract_expire_remind);
			if (!((String) dbMap.get("sys.birthday.remind"))
					.equals(sys_birthday_remind))
				dbConfigManager.setProperty("sys.birthday.remind",
						sys_birthday_remind);
			if (!((String) dbMap.get("sys.trial.expire.remind"))
					.equals(sys_trial_expire_remind))
				dbConfigManager.setProperty("sys.trial.expire.remind",
						sys_trial_expire_remind);
			if (!((String) dbMap.get("sys.salary.joinyear.calc"))
					.equals(sys_salary_joinyear_calc))
				dbConfigManager.setProperty("sys.salary.joinyear.calc",
						sys_salary_joinyear_calc);
			if (!sys_profile_save_history.equals(dbMap
					.get("sys.profile.save.history")))
				dbConfigManager.setProperty("sys.profile.save.history",
						sys_profile_save_history);
			if (!sys_position_max_exceed.equals(dbMap
					.get("sys.position.max.exceed")))
				dbConfigManager.setProperty("sys.position.max.exceed",
						sys_position_max_exceed);
		} catch (Exception e) {
			e.printStackTrace();
			return "input";
		}
		return "success";
	}

	public String getSys_contract_expire_remind() {
		return sys_contract_expire_remind;
	}

	public void setSys_contract_expire_remind(String sys_contract_expire_remind) {
		this.sys_contract_expire_remind = sys_contract_expire_remind;
	}

	public String getSys_birthday_remind() {
		return sys_birthday_remind;
	}

	public void setSys_birthday_remind(String sys_birthday_remind) {
		this.sys_birthday_remind = sys_birthday_remind;
	}

	public String getSys_trial_expire_remind() {
		return sys_trial_expire_remind;
	}

	public void setSys_trial_expire_remind(String sys_trial_expire_remind) {
		this.sys_trial_expire_remind = sys_trial_expire_remind;
	}

	public String getSys_salary_joinyear_calc() {
		return sys_salary_joinyear_calc;
	}

	public void setSys_salary_joinyear_calc(String sys_salary_joinyear_calc) {
		this.sys_salary_joinyear_calc = sys_salary_joinyear_calc;
	}

	public String getSys_profile_save_history() {
		return sys_profile_save_history;
	}

	public void setSys_profile_save_history(String sys_profile_save_history) {
		this.sys_profile_save_history = sys_profile_save_history;
	}

	public String getSys_position_max_exceed() {
		return sys_position_max_exceed;
	}

	public void setSys_position_max_exceed(String sys_position_max_exceed) {
		this.sys_position_max_exceed = sys_position_max_exceed;
	}

	private static final long serialVersionUID = 1L;
	private String sys_contract_expire_remind;
	private String sys_birthday_remind;
	private String sys_trial_expire_remind;
	private String sys_salary_joinyear_calc;
	private String sys_profile_save_history;
	private String sys_position_max_exceed;
	SysConfigManager dbConfigManager;
}
